﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using HPCloud.Common.Properties;

namespace HPCloud.Objects.DataAccess.Compute
{
    public class SSHClient
    {
        private string _username = "Administrator";
        private string _password;
        private string _address;
        private string _keypairName;
     
        private Settings _settings;

//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public SSHClient(Settings settings)
        {
            _settings = settings;
        }
//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public string KeypairName
        {
            get { return _keypairName; }
            set { _keypairName = value; }
        }
//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public string Address
        {
            get { return _address; }
            set { _address = value; }
        }
//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }       
//=============================================================================
/// <summary>
/// 
/// </summary>
//=============================================================================
        public void LaunchClient()
        {
           ProcessStartInfo startParams = new ProcessStartInfo();
           startParams.FileName         = this._settings.SSHClientPath;

           if (_keypairName != null)
           {
               string keyPath = _settings.KeyStoragePath + @"\HP\" + _keypairName + ".ppk";
               startParams.Arguments = " -i " + keyPath + " -ssh " + _username + "@" + _address;
           }
           //else
           //{
           //    //startParams.Arguments = _address + " -pw " + _password + " -ssh -l " + _username;
           //    startParams.Arguments = " -pw " + _password + " -ssh " + _username + "@" + _address;
           //}

            
            
            //startParams.Arguments        = " -i " + keyPath + " -ssh " + _username + "@" + _address + " -pw " + _password.Replace(@"\\r\\n", String.Empty);
           
           //startParams.Arguments = " -i " + keyPath + " -ssh " + _username + "@" + _address;

           Process.Start(startParams);
        }
    }
}

